package it.koutifaris.travianmap.dal.sqlservices.travianserver;

import it.koutifaris.travianmap.context.TravianMapContext;
import it.koutifaris.travianmap.dal.TravianServerService;
import it.koutifaris.travianmap.dal.TravianServerServiceFactory;
import it.koutifaris.travianmap.dal.TravianServerSettingsService;
import android.database.sqlite.SQLiteDatabase;

public class SqlTravianServerServiceFactory implements TravianServerServiceFactory {

	private final TravianMapContext context;

	public SqlTravianServerServiceFactory(TravianMapContext context) {
		this.context = context;
	}

	@Override
	public TravianServerService travianServerService() {
		return new SqlTravianServerService(newWritableDB());
	}

	@Override
	public TravianServerSettingsService travianServerSettingsService() {
		return new SqlTravianServerSettingsService(newWritableDB());
	}

	private SQLiteDatabase newWritableDB() {
		return context.getTravianServerDbHelper().getWritableDatabase();
	}
}
